package com.mercenary.wein.screenControl.ui.batch;

import com.mercenary.wein.screenControl.bean.DeviceBean;
import com.mercenary.wein.screenControl.command.CommandTool;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;


public class Shake extends JDialog {
    //Log log = LogFactory.getLog(AddAddressBookFriend.class);//面板1
    GroupCheckBoxPanel RequestJ1 = new GroupCheckBoxPanel();
    JPanel RequestJ2 = new JPanel();//面板2
    JPanel RequestJ3 = new JPanel();//面板2上的主操作面板
    JPanel LocationJ7 = new JPanel();
    JPanel LocationJ8 = new JPanel();
    JTextField num;
    JTextField start;
    JTextField end;
    static JFrame locationjf = new JFrame();
    String location;

    public Shake() {
        super(locationjf, "摇一摇");
        setBounds(200, 100, 700, 550);
        setLayout(new BorderLayout());
        setVisible(true);
        add(RequestJ1, BorderLayout.WEST);
        add(RequestJ2, BorderLayout.EAST);
        RequestJ1.setPreferredSize(new Dimension(180, 550));//设置大小
        RequestJ1.setBackground(Color.WHITE);
        RequestJ2.setLayout(new FlowLayout(FlowLayout.LEADING, 500, 10));
        RequestJ2.setPreferredSize(new Dimension(480, 550));
        RequestJ2.setBackground(Color.WHITE);
        //J2中的组件
        FlowLayout layout = new FlowLayout(FlowLayout.LEADING);
        RequestJ2.setLayout(layout);
        JPanel jp0 = new JPanel(new FlowLayout(FlowLayout.LEADING));
        JPanel jp1 = new JPanel(new FlowLayout(FlowLayout.LEADING));
        JPanel jp2 = new JPanel(new FlowLayout(FlowLayout.LEADING));
        final ExeModeButtonGroup jp3=new ExeModeButtonGroup(this);
        JPanel jp4 = new JPanel(new FlowLayout(FlowLayout.CENTER));
        JPanel jptime = new JPanel();
        jp0.setPreferredSize(new Dimension(500, 30));//设置大小
        jp1.setPreferredSize(new Dimension(500, 30));//设置大小
        jp2.setPreferredSize(new Dimension(500, 30));//设置大小
        jp3.setPreferredSize(new Dimension(500, 120));//设置大小
        jp4.setPreferredSize(new Dimension(500, 40));//设置大小
        SelectedNumLabel j1 = new SelectedNumLabel();

        //RequestJ1.registerObserver(j1);
        JLabel L1 = new JLabel("摇一摇次数:");
        JLabel L4 = new JLabel("~");
        JLabel L5 = new JLabel("秒");
        final JTextField num = new JTextField();
        num.setPreferredSize(new Dimension(35, 25));
        JTextField start = new JTextField("3");

        start.setPreferredSize(new Dimension(35, 25));
        JTextField end = new JTextField("5");
        end.setPreferredSize(new Dimension(35, 25));
        JCheckBox j3 = new JCheckBox("间隔");


        jp1.add(L1);
        jp1.add(num);
        jp2.add(j3);
        jp2.add(start);
        jp2.add(L4);
        jp2.add(end);

        JButton submit = new JButton("提交任务");

        jp4.add(submit);

        RequestJ2.add(jp1);
        RequestJ2.add(jp2);
        RequestJ2.add(jp3);
        RequestJ2.add(jp4);
        RequestJ2.validate();
        submit.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                CommandTool.shake(RequestJ1.getSelectedDevices()
                        ,num.getText().matches("\\d")?Integer.parseInt(num.getText()):1,
                        jp3.getExeModeBean());
            }
        });
    }



}

